package com.whcoding.multithreading.thred;

/**
 * @program: spring-boot-learning
 * @description:
 * @author: whcoding
 * @create: 2022-06-10 16:00
 **/
public class ThreadTest2 {

	private static boolean flag = true;

	public static void main(String[] args) throws InterruptedException {
		new Thread(() -> {
			System.out.println("1号线程启动，执行while循环");
			long num = 0;
			while (flag) {
				num++;
			}
			System.out.println("1号线程执行，num=" + num);
		}).start();

		Thread.sleep(1);

		new Thread(() -> {
			System.out.println("2号线程启动，更改变量flag值为false");
			setStop();
		}).start();
	}

	public static void setStop() {
		flag = false;
	}

}
